<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>添加</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
    <div style="padding: 50px">
        <div><span>姓名</span><input type="text" id="name" /></div>
        <div><span>密码</span><input type="text" id="pwd" /></div>
        <div><span>性别</span><input type="text" id="sex" /></div>
        <div><span>年龄</span><input type="text" id="age" /></div>
        <div><span>爱好</span><input type="text" id="love" /></div>
        <div><span>手机号</span><input type="text" id="phone" /></div>
        <div><span>邮箱</span><input type="text" id="email" /></div>

        <div><button id="submit">添加</button><button id="back">返回</button></div>
    </div>
</body>
</html>

<script>
    //点击button按钮处理
    $("#submit").click(function(){
        var name = $("#name").val();
        var pwd = $("#pwd").val();
        var sex = $("#sex").val();
        var age = $("#age").val();
        var love = $("#love").val();
        var phone = $("#phone").val();
        var email = $("#email").val();
        if (name==null || name=='' || pwd==null ||pwd=='' || sex==null || sex=='' ||age==null||age==''||love==null||love==''||phone==null||phone==''||email==null||email==''){
            alert("参数不能为空！")
            return false
        }
        $.ajax({
            url: "/user/save",// The URL for the request
            contentType : "application/json",
            data: JSON.stringify({name:name, pwd: pwd, sex: sex, age: age, love: love, phone: phone, email: email}),
            type: "POST",// Whether this is a POST or GET request
        }).done(function(res) {
            if (res.code==200){
                alert("添加成功")
                location.href = "index"
            } else {
                alert(res.message);
            }
        });
    })
    $("#back").click(function(){
        location.href = 'index'
    })
</script>
<style>
    span{
        font-size: 18px;
        margin-right: 10px;
        margin-top: 5px;
    }
    input{
        line-height: 32px;
        font-size: 20px;
        margin-top: 5px;
    }
    #submit{
        margin-top: 20px;
        line-height: 28px;
        width: 80px;
        color: aliceblue;
        background-color: darkseagreen;
        border-color: darkseagreen;
    }
    #back{
        margin-top: 20px;
        line-height: 28px;
        width: 80px;
        color: aliceblue;
        background-color: darkseagreen;
        border-color: darkseagreen;
    }
</style>